<?php
/**
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 *
 * This license is also available via the world-wide-web at
 * http://itdapps.ncsu.edu/bsd.txt
 *
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to itappdev@ncsu.edu so we can send you a copy immediately.
 *
 * @package    Index_Controller
 * @category   Controller
 * @copyright  Copyright (c) 2007 NC State University Office of Information Technology
 * @license    http://itdapps.ncsu.edu/bsd.txt  BSD License
 * @version    SVN: $Id: $
 */

/**
 * Main controller for the application
 *
 * @package    Index_Controller
 * @category   Controller
 * @copyright  Copyright (c) 2007 NC State University Office of Information Technology
 */
class IndexController extends Zend_Controller_Action 
{   
          
    /**
     * shows the homepage
     *
     */
    public function indexAction()
    {
        $gdataOauthSecret = Zend_Registry::get('gdataOauthSecret');
        $gdataOauthKey    = Zend_Registry::get('gdataOauthKey');
        $gdataDomain      = Zend_Registry::get('gdataDomain');
        $gdataUsername    = Zend_Registry::get('gdataUsername');
        $gdataPassword    = Zend_Registry::get('gdataPassword');
        
        unset($_POST);
        
        $get = Zend_Registry::get('getFilter');
        
        $title = 'Lookup User';
        
        if (isset($get->userId)) {

            $this->view->userId = $get->userId;
                        
            $user = new Gdata_Apps_User();
            
            $thisUser = $user->find($get->userId);
            $this->view->thisUser = $thisUser;
            
            if (!is_null($thisUser)) {
                $title .= ": " . ((!is_null($thisUser)) ? $thisUser->name->givenName . ' ' . $thisUser->name->familyName . ' (' . $thisUser->login->username . ')' : $thisUser->login->username);
            }
            
            $tabs = Zend_Registry::get('lookupTabs');
            
            foreach ($tabs as $key => $value) {
                if (!$this->_helper->hasAccess('index', 'tab_' . $value['link'])) {
                    unset($tabs[$key]);
                }
            }
            
            $this->view->tabs = $tabs;
        }
        
        $this->view->headScript()->appendFile($this->view->baseUrl() . '/public/scripts/jquery.jProgressBar.js');
        
        $this->view->messages = $this->_helper->flashMessenger->getMessages();
        $this->view->gdataDomain = $gdataDomain;
                
        $this->_helper->pageTitle($title);        
    }
    
    public function backupDocsAction()
    {
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNeverRender();
        
        $export = new Export();
        $export->exportDocs();
        
        //$docs = new Gdata_Apps_Docs();
        //$docs->getDocsList('njyoung');
    }
}